import 'package:flutter/material.dart';
import 'package:flutter_application_1/routes/app_routes.dart';
import 'package:get/get.dart';

import 'my_logic.dart';

class MyPage extends StatelessWidget {
  MyPage({Key? key}) : super(key: key);

  final MyLogic logic = Get.put(MyLogic());

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: EdgeInsets.all(16),
      child: Stack(
        children: [
          Obx(() {
            return Text('My Page 点击了${logic.num.value}次');
          }),
          Padding(
            padding: EdgeInsets.only(top: 20),
            child: ElevatedButton(
              onPressed: () {
                logic.add();
              },
              child: Icon(Icons.add),
            ),
          ),
          Padding(
            padding: EdgeInsets.only(top: 80),
            child: Row(
              children: [
                ElevatedButton(
                  onPressed: logic.update_users,
                  child: Text(' 修改信息'),
                ),
                Obx(() {
                  return Text("姓名：${logic.users["name"]}");
                }),
                Text("age：${logic.users["age"]}"),
              ],
            ),
          ),
          Padding(
            padding: EdgeInsets.only(top: 140),
            child: ElevatedButton(
              onPressed:
                  () => Get.toNamed(
                    AppRoutes.list,
                    parameters: {'id': '12'},
                    // 传控制器(logic)引用（非拷贝）
                    arguments: {'msg': '我是上个我的页面的数据', 'mylogic': logic},
                  ),
              child: Text('跳转list页面'),
            ),
          ),
        ],
      ),
    );
  }
}
